package fhp.hlhj.giantfold.adapter

import android.content.Context
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.javaBean.CashDetailBean
import fhp.hlhj.giantfold.javaBean.GainDetailBean
import java.text.DecimalFormat
import java.util.ArrayList

/**
 * author: FHP
 * data: on 2018\1\29 0029 10:39
 * E-Mail: 103945089@qq.com
 */
class AccountGainlListAdp(private val context: Context, private val datas:ArrayList<GainDetailBean.DataBean>):BaseAdapter() {
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var convertView=convertView
        if (convertView==null){
            convertView=LayoutInflater.from(context).inflate(R.layout.account_detail_list_item,null)
        }
        val itemTittle = convertView?.findViewById<TextView>(R.id.itemTitle)
        val itemNum = convertView?.findViewById<TextView>(R.id.itemNum)
        val itemTime = convertView?.findViewById<TextView>(R.id.itemTime)
        val data = datas[position]
        val format = DecimalFormat("0.000")
        itemNum?.text=format.format(data.money.toDouble()).toString()
        itemTime?.text=data.time
        itemTittle?.text=data.remark

        return convertView!!
    }

    override fun getItem(position: Int): Any {
        return datas[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return datas.size
    }


    fun <T : View> View.findViewOften(viewId: Int): T {
        var viewHolder: SparseArray<View> = tag as? SparseArray<View> ?: SparseArray()
        tag = viewHolder
        var childView: View? = viewHolder.get(viewId)
        if (null == childView) {
            childView = findViewById(viewId)
            viewHolder.put(viewId, childView)
        }
        return childView as T
    }
}